package model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public final class Contact implements ContactInterface {

    private String fName;
    private String lName;
    private String hAddress;
    private String cAddress;
    private List<String> pPhones;
    private List<String> cPhones;
    private String homePage;
    private List<String> emails;
    private String photo;
    private Map<String, String> others;
    private List<String> groups;
    private Date insertDate;

    public Contact(String fName, String lName, String hAddress,
            String cAddress, List<String> pPhones, List<String> cPhones,
            String homePage, List<String> emails, String photo,
            Map<String, String> others, List<String> groups, Date insertDate) {
        super();

        this.fName = fName;
        this.lName = lName;
        this.hAddress = hAddress;
        this.cAddress = cAddress;
        this.pPhones = pPhones;
        this.cPhones = cPhones;
        this.homePage = homePage;
        this.emails = emails;
        this.photo = photo;
        this.others = others;
        this.groups = groups;
        this.insertDate = insertDate;
    }

    public Contact(String fName, String lName) {
        super();
        this.fName = fName;
        this.lName = lName;

    }

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getlName() {
        return lName;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }

    public String gethAddress() {
        return hAddress;
    }

    public void sethAddress(String hAddress) {
        this.hAddress = hAddress;
    }

    public String getcAddress() {
        return cAddress;
    }

    public void setcAddress(String cAddress) {
        this.cAddress = cAddress;
    }

    public String getHomePage() {
        return homePage;
    }

    public void setHomePage(String homePage) {
        this.homePage = homePage;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public Date getInsertDate() {
        return insertDate;
    }

    // pPhones
    public void addpPhone(String pPhone) {
        this.pPhones.add(pPhone);
    }

    public void delpPhone(String pPhone) {
        this.pPhones.remove(pPhone);
    }

    public List<String> getpPhones() {
        return new ArrayList<String>(this.pPhones);
    }

    // cPhones
    public void addcPhone(String cPhone) {
        this.cPhones.add(cPhone);
    }

    public void delcPhone(String cPhone) {
        this.cPhones.remove(cPhone);
    }

    public List<String> getcPhones() {
        return new ArrayList<String>(this.cPhones);
    }

    // E-mails
    public void addEmails(String email) {
        this.emails.add(email);
    }

    public void delEmails(String email) {
        this.emails.remove(email);
    }

    public List<String> getEmails() {
        return new ArrayList<String>(this.emails);
    }

    // Others
    public void addOther(String key, String value) {
        this.others.put(key, value);
    }

    public void delOther(String key) {
        this.others.remove(key);
    }

    public Map<String, String> getOthers() {
        return this.others;
    }

    // Groups
    public void addGroups(String group) {
        this.groups.add(group);
    }

    public void delGroups(String group) {
        this.groups.remove(group);
    }

    public List<String> getGroups() {
        return this.groups;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((fName == null) ? 0 : fName.hashCode());
        result = prime * result + ((lName == null) ? 0 : lName.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Contact other = (Contact) obj;
        if (fName == null) {
            if (other.fName != null) {
                return false;
            }
        } else if (!fName.equals(other.fName)) {
            return false;
        }
        if (lName == null) {
            if (other.lName != null) {
                return false;
            }
        } else if (!lName.equals(other.lName)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Contact [fName=" + fName + ", lName=" + lName + ", hAddress="
                + hAddress + ", cAddress=" + cAddress + ", pPhones=" + pPhones
                + ", cPhones=" + cPhones + ", homePage=" + homePage
                + ", emails=" + emails + ", photo=" + photo + ", others="
                + others + ", groups=" + groups + ", insertDate=" + insertDate
                + "]";
    }

    public String toStringCSV() {
        return "" + fName + ", " + lName + ", " + hAddress + ", " + cAddress + ", " + pPhones.toString().replace(",", ";") + ", " + cPhones.toString().replace(",", ";") + ", " + homePage + ", " + emails.toString().replace(",", ";") + ", " + photo + ", " + others.toString().replace(",", ";") + ", " + groups.toString().replace(",", ";") + ", " + insertDate.getTime();
    }

}
